/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

#ifndef ENUMABSTRACT_H_
#define ENUMABSTRACT_H_

#include <boost/iterator/iterator_facade.hpp>

#include "MeAbstract.h"
#include "IoAbstract.h"

using namespace boost;

template<class Enum, typename Int = int>
class EnumAbstract
	: public MeAbstract<Enum>
	, public IoAbstract<Enum> {
public:
	class Iterator
		: public iterator_facade<Iterator, Enum, bidirectional_traversal_tag, Enum>
	{
	public:
		static const Iterator end() {
			return Enum::END();
		}

		static const Iterator rend() {
			return Enum::REND();
		}

		static Iterator begin() {
			return Enum::BEGIN();
		}

		static Iterator rbegin() {
			return Enum::RBEGIN();
		}
	public:
		Iterator() : _enum(Enum::NIL()) {}
		Iterator(Enum _enum) : _enum(_enum) {}

		void increment() {
			++this->_enum;
		}

		void decrement() {
			--this->_enum;
		}

		bool equal(Iterator const& other) const {
			return this->_enum == other._enum;
		}

		const Enum dereference() const {
			return this->_enum;
		}

	private:
		Enum _enum;
	};
public:
	bool operator!=(const Enum _enum) const {
		return !(this->me_c() == _enum);
	}
	bool isNil() const { return this->me_c() == Enum::NIL(); }
};

#endif /* ENUMABSTRACT_H_ */
